package gui;

import javax.swing.*;
import java.awt.Component;
import java.awt.Color;
import javax.swing.table.TableCellRenderer;

/**
 * A class to implement Combo boxes in a JTable
 * @author Sarah Wegner
 */
public class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
    public MyComboBoxRenderer(String[] items) {
        super(items);
    }//MyComboBoxRenderer

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        int colCount = table.getColumnCount();
        String colName = table.getColumnName(colCount-1);

        if (isSelected) {
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        }//if
        else if((column < colCount) && (column >=0) && (colName.equals("Deleted")) && (((Boolean)table.getValueAt(row,colCount-1)) == true)){
            setForeground(table.getForeground());
            setBackground(Color.getHSBColor(0, 0, (float)0.863));
        }//else-if
        else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }//else

        // Select the current value
        setSelectedItem(value);
        return this;
    }//getTableCellRendererComponent

}//MyComboBoxRenderer